home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT19.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.4 KB  |  97 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 19                         
  5.                                           
  6.  This program loads in some sprites created with the WGT Sprite Editor.      
  7.                                           
  8.  *** PROJECT ***                                                             
  9.  This program requires the file WGT5_WC.LIB to be linked.                    
  10.                                           
  11.  *** DATA FILES ***                                                          
  12.  Make sure that SPACE.SPR is in your executable directory.                   
  13.                                WATCOM C++ VERSION 
  14. ==============================================================================
  15. */
  16.  
  17. #include <wgt5.h>
  18.  
  19.  
  20. void main(void)
  21. {
  22.   block screen1;          /* one virtual screen */
  23.   block sprites[10];      /* An array of blocks to load the sprites into.
  24.                  Version 5.0 allows for any number to be
  25.                  loaded in, as long as you pass the same size
  26.                  of the array to the wloadsprites and wfreesprites
  27.                  commands. */
  28.   short y;
  29.   short sp;
  30.   short oldmode;
  31.   color palette[256];
  32.  
  33.   if ( !vgadetected () )
  34.   {
  35.     printf("Error - VGA card required for any WGT program.\n");
  36.     exit (0);
  37.   }
  38.   printf ("WGT Example #19\n\n");
  39.   printf ("This program loads some images from a sprite file. Press the left mouse\n");
  40.   printf ("button to flip between the images. Press the right mouse button to end the\n");
  41.   printf ("demo and display image dimensions.  The top image uses wputblock and\n");
  42.   printf ("the bottom image uses wresize with xray mode.\n");
  43.   printf ("\n\nPress any key to continue.\n");
  44.   getch ();
  45.  
  46.   oldmode = wgetmode ();
  47.   vga256 ();
  48.   wloadsprites (palette, "space.spr", sprites, 0, 9);
  49.   /* loads the first 10 sprites */
  50.   wsetpalette(0, 255, palette);
  51.  
  52.   screen1 = wnewblock(0, 0, 319, 199);
  53.   wsetscreen (screen1);
  54.  
  55.   sp = 1;                       /* sprites always start at 1 in the array */
  56.   minit ();
  57.   msetbounds (0, 0, 160, 199);
  58.  
  59.   do {
  60.     for (y = 0; y < 200; y++)
  61.     {
  62.       wsetcolor (y);
  63.       wline (0, y, 319, y); /* clear the screen by drawing horz lines (fast) */
  64.     }
  65.     wputblock (0, 0, sprites[1], 0);
  66.     if (sprites[sp] != NULL)
  67.      {
  68.       wputblock (mouse.mx, mouse.my, sprites[sp], 1);   /* put the block using xray mode at mouse position */
  69.  
  70.       wflipblock (sprites[sp], 0); /* flip the sprite vertically */
  71.       wresize (mouse.mx - 20, mouse.my + 50, mouse.mx + 20, mouse.my + 90,
  72.            sprites[sp], 1); 
  73.       /* resize the sprite using xray mode just below the first one */
  74.       
  75.       wflipblock (sprites[sp], 0); /* flip it back to normal */
  76.      }
  77.     wcopyscreen (0, 0, 160, 199, screen1, 0, 0, NULL);  /* copy the whole screen */
  78.  
  79.     if (mouse.but == 1)  /* Show the next sprite */
  80.     {
  81.       sp++;
  82.       if (sp > 9) 
  83.     sp = 1;
  84.       noclick ();
  85.     }
  86.  
  87.   } while (mouse.but != 2);            /* right button exits */
  88.   msetbounds (0, 0, 319, 199);
  89.   mdeinit ();                   /* Deinitialize the mouse handler */
  90.   wfreeblock (screen1);
  91.   wsetmode (oldmode);
  92.   for (y = 1; y < 10; y++)
  93.     if (sprites[y] != NULL)
  94.       printf ("#%2d is %d by %d\n", y, wgetblockwidth (sprites[y]), wgetblockheight (sprites[y]));
  95.   wfreesprites (sprites, 0, 9);  /* frees all sprites in that array */
  96. }
  97.